/*
 * StaticLogClass.cpp
 *
 *  Created on: Mar 6, 2013
 *      Author: loadar
 */

#include "StaticLogClass.h"
#include <iostream>
#include <string>
#include <map>

namespace staticmember {

std::map<std::string, StaticLogClass*> *StaticLogClass::classMap = new std::map<std::string, StaticLogClass*>();

void StaticLogClass::addStaticLogClass(StaticLogClass* logClass)
{
	std::string logClassName = logClass->className;
	std::cout << "---------add value start--------" << logClassName << std::endl;
	//StaticLogClass::classMap->insert(std::pair<std::string, StaticLogClass*>(logClassName, logClass));
	std::cout << "---------add value end--------" << std::endl;
}
StaticLogClass* StaticLogClass::getStaticLogClass(std::string name)
{
	StaticLogClass *result = NULL;
	std::map<std::string, StaticLogClass*>::iterator it;
	for (it = StaticLogClass::classMap->begin(); it != StaticLogClass::classMap->end(); it++)
	{
		if (it->first == name)
		{
			result = it->second;
			break;
		}
	}
	return result;
}

StaticLogClass::StaticLogClass(std::string name, IStaticLog::pCreateStaticLog fun)
{
	std::cout << "---------class init--------" << std::endl;
	this->className = name;
	this->createFun = fun;

	std::cout << "---------add start--------" << std::endl;
	StaticLogClass::addStaticLogClass(this);
	std::cout << "---------add ok--------" << std::endl;
}

StaticLogClass::~StaticLogClass()
{

}

IStaticLog* StaticLogClass::newStaticLogInstance()
{
	IStaticLog *log = NULL;

	if (this->createFun != NULL)
	{
		log = this->createFun();
	}

	return log;
}

} /* namespace staticmember */
